﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QFlow.Data
{
    public partial class SaleItem
    {
        bool _IsDirty;

        public SaleItem Clone()
        {
            return new SaleItem
            {
                DiscountPercent = this.DiscountPercent,
                PurchaseItemId = this.PurchaseItemId,
                ItemType = this.ItemType,
                Notes = this.Notes,
                StockableProduct = this.StockableProduct,
                Quantity = this.Quantity,
                TaxesPercent = this.TaxesPercent,
                UnitPrice = this.UnitPrice,
                User = this.User,
                PurchaseItem = this.PurchaseItem,
                ParentSaleItemID = this.ParentSaleItemID,
                ProfitPercent = this.ProfitPercent,
            };
        }

        public bool IsAttached()
        {
            //return this.PropertyChanging != null;
            return this.SaleItemID != 0;
        }

        public bool IsDirty()
        {
            return _IsDirty;
        }

        partial void OnLoaded()
        {
            if (PropertyChanged == null)
                PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PurchaseItem_PropertyChanged);
        }

        partial void OnCreated()
        {
            if (PropertyChanged == null)
                PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PurchaseItem_PropertyChanged);
        }

        void PurchaseItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            _IsDirty = true;
        }
    }
}
